package br.com.honorato.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import br.com.honorato.enun.EUserAppStatus;
import br.com.honorato.enun.EYesNo;

/**
 * The persistent class for the tb_usuario database table.
 * 
 */
@Entity
// @Table(name="TB_USER",
// uniqueConstraints={@UniqueConstraint(columnNames={"CD_LOGIN"})})
@Table(name = "tb_user", uniqueConstraints =
{ @UniqueConstraint(columnNames =
{ "CD_LOGIN" }) })
@Inheritance(strategy = InheritanceType.JOINED)
public class UserApp implements Serializable
{

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID_USER")
	private Integer idUser;

	@Column(name = "CD_LOGIN")
	@NotBlank(message = "{user.login.notBlank}")
	@Length(max = 100, message = "{user.login.MaxLength}")
	private String login;

	@Column(name = "DE_PASSWORD")
	private String password;

	@Column(name = "NM_USER")
	@NotBlank(message = "{user.name.notBlank}")
	@Length(max = 100, message = "{user.name.MaxLength}")
	private String name;

	@Enumerated(EnumType.STRING)
	@Column(name = "IN_CHANGE_PASSWORD")
	@NotNull(message = "{user.changePassword.notNull}")
	private EYesNo changePassword;

	@Enumerated(EnumType.STRING)
	@Column(name = "IN_STATUS")
	@NotNull(message = "{user.status.notNull}")
	public EUserAppStatus status;

	@Column(name = "DH_ALTERACAO")
	@Temporal(value = TemporalType.TIMESTAMP)
	private Date dataAlteracao;

	public UserApp()
	{}

	public UserApp(Integer iduser, String login, String password)
	{
		super();
		this.idUser = iduser;
		this.login = login;
		this.password = password;
	}

	public String getLogin()
	{
		return login;
	}

	public void setLogin(String login)
	{
		this.login = login;
	}

	public String getPassword()
	{
		return password;
	}

	public void setPassword(String password)
	{
		this.password = password;
	}

	public Integer getIdUser()
	{
		return idUser;
	}

	public void setIdUser(Integer idUser)
	{
		this.idUser = idUser;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public EUserAppStatus getStatus()
	{
		return status;
	}

	public void setStatus(EUserAppStatus status)
	{
		this.status = status;
	}

	public EYesNo getChangePassword()
	{
		return this.changePassword;
	}

	public void setChangePassword(EYesNo changePassword)
	{
		this.changePassword = changePassword;
	}

	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
		{
			return true;
		}
		if (obj == null)
		{
			return false;
		}
		if (getClass() != obj.getClass())
		{
			return false;
		}

		if (!login.equals(((UserApp) obj).getLogin()))
		{
			return false;
		}
		else
		{
			return true;
		}
	}

	@Override
	public String toString()
	{
		return "Identificador: " + idUser + " Login: " + login;
	}

	public Date getDataAlteracao()
	{
		return dataAlteracao;
	}

	public void setDataAlteracao(Date data)
	{
		this.dataAlteracao = data;
	}
}